package com.example.composableexample

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp


@Preview
@Composable
fun WithoutStateHoistingMethodExample() {
    val name = remember { mutableStateOf("") }
    HelloContentWithoutStateHoisting(name.value) { name.value = it }
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HelloContentWithoutStateHoisting(name: String, onNameChange: (String) -> Unit) {

    Column(modifier = Modifier.padding(16.dp)) {
        Text(
            text = "Hello, $name",
            modifier = Modifier.padding(bottom = 8.dp),
            style = MaterialTheme.typography.titleMedium
        )
        OutlinedTextField(
            value = name,
            onValueChange = {
                onNameChange(it)
            },
            label = { Text("Name") }
        )
    }
}